﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t302Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t302_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t302Mgr mgr = new t302Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t302(e.Parameters[t302_Filter.ParamPrefix]));
            IList<t302> list = mgr.FindAllByPage_t302(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t302_Filter.ParamPrefix]);
            t302_MainStore.DataSource = list;
            t302_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t302Mgr mgr = new t302Mgr();
            RowSelectionModel sm = t302_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t302 _t302 = new t302();
                _t302.t302_01 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t302(_t302))
                {
                    log.Debug("t302中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t302_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t302Mgr mgr = new t302Mgr();
            t302 _t302 = new t302();
            if (Hid.Text.Length > 0)
                _t302 = mgr.FindById_t302(int.Parse(Hid.Text));
            
			_t302.t302_02 = Txtt302_02.Text.Trim();
			_t302.t302_03 = Txtt302_03.Text.Trim();
			_t302.t302_04 = Txtt302_04.Text.Trim();
			_t302.t302_05 = Txtt302_05.Text.Trim();
			_t302.t302_06 = Txtt302_06.Text.Trim();
			_t302.t302_07 = Txtt302_07.Text.Trim();
			_t302.t302_08 = Txtt302_08.Text.Trim();
			_t302.t302_09 = Txtt302_09.Text.Trim();
			_t302.t302_10 = Txtt302_10.Text.Trim();
			_t302.t302_11 = Txtt302_11.Text.Trim();
			_t302.t302_12 = Txtt302_12.Text.Trim();
			_t302.t302_13 = Txtt302_13.Text.Trim();
			_t302.t302_14 = Txtt302_14.Text.Trim();
			_t302.t302_15 = Txtt302_15.Text.Trim();
			_t302.t302_16 = Txtt302_16.Text.Trim();
			_t302.t302_17 = Txtt302_17.Text.Trim();
			_t302.t302_18 = Txtt302_18.Text.Trim();
			_t302.t302_19 = Txtt302_19.Text.Trim();
			_t302.t302_20 = Txtt302_20.Text.Trim();
			_t302.t302_21 = Txtt302_21.Text.Trim();
			_t302.t302_22 = Txtt302_22.Text.Trim();
			_t302.t302_23 = Txtt302_23.Text.Trim();
			_t302.t302_24 = Txtt302_24.Text.Trim();
			_t302.t302_25 = Txtt302_25.Text.Trim();
			_t302.t302_26 = Txtt302_26.Text.Trim();
			_t302.t302_27 = Txtt302_27.Text.Trim();
			_t302.t302_28 = Txtt302_28.Text.Trim();
			_t302.t302_29 = Txtt302_29.Text.Trim();
			_t302.t302_30 = Txtt302_30.Text.Trim();
			_t302.t302_31 = Txtt302_31.Text.Trim();
			_t302.t302_32 = Txtt302_32.Text.Trim();
			_t302.t302_33 = Txtt302_33.Text.Trim();
			_t302.t302_34 = Txtt302_34.Text.Trim();
			_t302.t302_35 = Txtt302_35.Text.Trim();
			_t302.t302_36 = Txtt302_36.Text.Trim();
			_t302.t302_37 = Txtt302_37.Text.Trim();
			_t302.t302_38 = Txtt302_38.Text.Trim();
			_t302.t302_39 = Txtt302_39.Text.Trim();
			_t302.t302_40 = Txtt302_40.Text.Trim();
			_t302.t302_41 = Txtt302_41.Text.Trim();
			_t302.t302_42 = Txtt302_42.Text.Trim();
			_t302.t302_43 = Txtt302_43.Text.Trim();
			_t302.t302_44 = Txtt302_44.Text.Trim();
			_t302.t302_45 = Txtt302_45.Text.Trim();
			_t302.t302_70 = Txtt302_70.Text.Trim();
			_t302.t302_71 = Txtt302_71.Text.Trim();
			_t302.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t302(_t302);
            else
                isok = mgr.Add_t302(_t302);
            if (isok)
            {
                t302_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t302中执行了保存（插入或修改），并成功");
                t302_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}